-
Notifications
You must be signed in to change notification settings - Fork 12.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Use copied
instead of manual map
#117549
Use copied
instead of manual map
#117549
Conversation
r? @b-naber (rustbot has picked a reviewer for you, use r? to override) |
@@ -41,8 +41,7 @@ impl<'hir> LoweringContext<'_, 'hir> { | |||
} | |||
// Merge attributes into the inner expression. | |||
if !e.attrs.is_empty() { | |||
let old_attrs = | |||
self.attrs.get(&ex.hir_id.local_id).map(|la| *la).unwrap_or(&[]); | |||
let old_attrs = self.attrs.get(&ex.hir_id.local_id).copied().unwrap_or(&[]); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
let old_attrs = self.attrs.get(&ex.hir_id.local_id).copied().unwrap_or(&[]); | |
let old_attrs = self.attrs.get(&ex.hir_id.local_id).copied().unwrap_or_default(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't feel strongly about it, but very slightly prefer unwrap_or
: it's both fewer keystrokes and slightly less cognitive load for the reader (no need to consider the type or what its Default
implementation is).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Both are present in the codebase, I don't think this should be changed, but if anything I think it should be in a follow-up PR.
@bors r+ rollup |
Use `copied` instead of manual `map`
How did you find these? Is it a clippy lint? |
Apparently there is one: https://rust-lang.github.io/rust-clippy/master/#/map_clone |
…iaskrgr Rollup of 7 pull requests Successful merges: - rust-lang#117338 (Remove asmjs) - rust-lang#117549 (Use `copied` instead of manual `map`) - rust-lang#117745 (Emit smir) - rust-lang#117964 (When using existing fn as module, don't claim it doesn't exist) - rust-lang#118006 (clarify `fn discriminant` guarantees: only free lifetimes may get erased) - rust-lang#118016 (Add stable mir members to triagebot config) - rust-lang#118022 (Miri subtree update) r? `@ghost` `@rustbot` modify labels: rollup
Rollup merge of rust-lang#117549 - DaniPopes:more-copied, r=b-naber Use `copied` instead of manual `map`
No description provided.